package com.gxa.hualian.service.impl;

import com.gxa.hualian.exception.BusinessException;
import com.gxa.hualian.mapper.GetMapper;
import com.gxa.hualian.mapper.UserMapper;
import com.gxa.hualian.pojo.Get;
import com.gxa.hualian.pojo.User;
import com.gxa.hualian.service.UserService;
import com.gxa.hualian.util.JsonResult;
import org.springframework.data.redis.core.BoundValueOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Author 杨天可
 * @Date 2020/10/21 10:21
 * @Version 1.0
 */
@Service("userService")
public class UserServiceImpl implements UserService {
    @Resource
    UserMapper userMapper;
    @Resource
    GetMapper getMapper;


    @Override
    public User findByPohne(String phone) {
        User user = new User();
        user.setPhone(phone);
        return userMapper.selectOne(user);
    }

    @Override
    public int insert(User user) {
        return  userMapper.insert(user);
    }

    @Override
    public Map login(String phone) {
        User user = new User();
        if (phone == null || phone.equals("")) {
            throw new BusinessException("电话不能为空");
        }
        //通过电话判断用户是否存在
        JsonResult jsonResult = new JsonResult();
        user.setPhone(phone);
        User user1 = userMapper.selectOne(user);
        if (user1 == null) {
            jsonResult.setMsg("该号码还未注册");
            jsonResult.setCode("400");
        } else {
            jsonResult.setMsg("登录成功");
            jsonResult.setCode("200");
            jsonResult.setData(user);
        }
        return jsonResult.getValues();
    }

    @Override
    public Map<String,Object> getTktList(String phone) {
        Get get = new Get();
        JsonResult jsonResult = new JsonResult();
        get.setUserPhone(phone);
        List<Map<String, Object>> list = getMapper.findList(phone);
        jsonResult.setData("内江优惠券"+list);
        List<Map<String, Object>> list1 = getMapper.findList("18398924574");
        jsonResult.setData("巴中优惠券"+list1);
        return jsonResult.getValues();
    }


}
